using Sirenix.OdinInspector;

namespace Demo.PlayerLoop
{
    using UnityEngine;
    using UnityEngine.LowLevel;

    public class PlayerLoopExample : MonoBehaviour
    {
        //[ContextMenu("Print PlayerLoop Structure")]
        [Button("Print PlayerLoop Structure")]
        void PrintPlayerLoopStructure()
        {
            var playerLoop = PlayerLoop.GetCurrentPlayerLoop();
            PrintSystem(playerLoop, 0);
        }
    
        void PrintSystem(PlayerLoopSystem system, int depth)
        {
            string indent = new string(' ', depth * 4);
            Debug.Log($"{indent}[{system.type?.Name ?? "Root"}]");
        
            if (system.subSystemList != null)
            {
                foreach (var subSystem in system.subSystemList)
                {
                    PrintSystem(subSystem, depth + 1);
                }
            }
        }
    
        [ContextMenu("Print Execution Order")]
        void PrintExecutionOrder()
        {
            Debug.Log("===== Unity 每帧执行顺序 =====");
            Debug.Log("1. Initialization (首帧)");
            Debug.Log("2. EarlyUpdate");
            Debug.Log("   - 输入系统");
            Debug.Log("   - 网络系统");
            Debug.Log("3. FixedUpdate (固定时间步)");
            Debug.Log("   - MonoBehaviour.FixedUpdate");
            Debug.Log("   - 物理模拟");
            Debug.Log("4. PreUpdate");
            Debug.Log("   - 物理更新");
            Debug.Log("5. Update");
            Debug.Log("   - MonoBehaviour.Update ← 你的代码在这里");
            Debug.Log("6. PreLateUpdate");
            Debug.Log("   - MonoBehaviour.LateUpdate");
            Debug.Log("7. PostLateUpdate");
            Debug.Log("   - UI 更新");
            Debug.Log("   - 渲染准备");
            Debug.Log("8. Rendering (渲染线程)");
        }
    }
}